#!/usr/bin/env python
# -*- coding:utf-8 -*-
#r,w分开写

import socket
import select
import time
from Queue import Queue

ip_port=('127.0.0.1',8888)
sk = socket.socket()
sk.bind(ip_port)
sk.listen(5)    #5，表示内核已经接到了连接请求，但服务器还没有调用accept进行处理的连接个数最大为5
sk.setblocking(False)

inputs=[sk]
outputs=[]

while True:
    rlist,wlist,e=select.select(inputs,outputs,[],0.05)
    # time.sleep(2)
    for r in rlist:
        if r==sk:   #客户端句柄
            conn,address=r.accept()
            inputs.append(conn)
            print address

        else:
            client_data=r.recv(1024)
            if client_data:
                outputs.append(r)

    for w in wlist:
        w.sendall("123")
        outputs.remove(w)


